package com.bianhua.front;

import com.bianhua.entity.Company;
import com.bianhua.entity.Post;
import com.bianhua.service.CompanyService;
import com.bianhua.service.PostService;
import com.bianhua.utils.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/f/post/")
public class PostFront {

    @Autowired
    PostService postService;

    @Autowired
    CompanyService companyService;


    public void saveOrUpdate(HashMap hm){
        int i = postService.countMahout(hm);
        if(i>0){
            postService.updateMahout(hm);
        }else{
            postService.createMahout(hm);
        }

    }

    /*name:'' 职位名称,
    salary:'' 薪资范围,
    education:'' 学历,
    company:'' 公司,
    type:'' 类型,
    size:'', 企业规模*/
    @PostMapping("query")
    public Map<String,Object> getPostList(@RequestBody HashMap map){
        PageInfo<HashMap> postList = postService.getPostList(map);
        return Result.ok(postList);
    }

    @GetMapping("info")
    public Result detail(Integer id){
        Post detail = postService.detail(id);
        Company company = companyService.detail(detail.getCompanyId());
        detail.setCompany(company);
        return Result.ok(detail);
    }

}

